package com.lbs.jiepiaisi.activity;

import com.lbs.jiepiaisi.base.BaseActivity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.amap.api.maps.AMap;
import com.amap.api.maps.CameraUpdateFactory;
import com.amap.api.maps.MapView;
import com.amap.api.maps.model.BitmapDescriptor;
import com.amap.api.maps.model.CameraPosition;
import com.amap.api.maps.model.LatLng;
import com.amap.api.maps.model.Marker;
import com.amap.api.services.core.LatLonPoint;
import com.amap.api.services.geocoder.GeocodeResult;
import com.amap.api.services.geocoder.GeocodeSearch;
import com.amap.api.services.geocoder.RegeocodeQuery;
import com.amap.api.services.geocoder.RegeocodeResult;
import com.lbs.jiepiaisi.R;
import com.lbs.jiepiaisi.bean.LocationBean;
import com.lbs.jiepiaisi.bean.TrackEntity;
import com.lbs.jiepiaisi.bean.UserEntity;
import com.lbs.jiepiaisi.bean.VinList;
import com.lbs.jiepiaisi.biz.LocationBiz;
import com.lbs.jiepiaisi.biz.LoginAccountBiz;
import com.lbs.jiepiaisi.biz.TrackBiz;
import com.lbs.jiepiaisi.manager.SharePreferenceManager;
import com.lbs.jiepiaisi.manager.VinListPoiOverlay;
import com.lbs.jiepiaisi.utils.ButtonUtil;
import com.lbs.jiepiaisi.utils.Constant;
import com.lbs.jiepiaisi.utils.VinEvent;
import com.lbs.jiepiaisi.utils.WindowSizeUtil;
import com.lbs.jiepiaisi.view.WaitingDialogControll;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by yu on 2020-07-27 14:00.
 * Description:
 */
public class VinIndexActivity extends BaseActivity implements
        AMap.OnMapClickListener, AMap.OnMarkerClickListener,
        View.OnClickListener, AMap.InfoWindowAdapter, GeocodeSearch.OnGeocodeSearchListener {
    private VinList vinList;
    private MapView mapView;//地图
    private AMap aMap;//地图控制器对象
    private static int flag = 0;//infowindow点击更多切换按钮状态
    private LinearLayout liner_search;//搜索
    private SelCarsReceiver selCarsReceiver;//接收坐标点的广播
    private TrackReceiver trackReceiver;//接收实时跟踪中的接口数据广播
    private LocationReceiver locationReceiver;//接收根据经纬度查询的位置信息
    private VinList equipmentEntity;
    private TrackEntity trackEntity;
    private SharePreferenceManager mSharePreference = null;
    private GeocodeSearch geocodeSearch;//逆地理编码转换对象
    private String addressName;//当前地址
    private String possionTime;//当前定位时间
    VinListPoiOverlay poiOverlay;

    private ImageButton mBackImageButton;

    private TextView mTitleTv;

    private View popView; //显示弹框

    private boolean isFirst = false;
    private boolean oldShowFlag = true;
    private Marker showMarker = null;

    private UserEntity userEntity;

    private TextView tv_dress;

    private TextView mTvRight;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EventBus.getDefault().register(this);
        setContentView(R.layout.activity_car_no_login);
        mapView = (MapView) findViewById(R.id.map);
        mapView.onCreate(savedInstanceState);// 此方法必须重写
        selCarsReceiver = new SelCarsReceiver();
        getApplicationContext().registerReceiver(selCarsReceiver, new IntentFilter(Constant.ACCOUNT_VIN_LOGIN));
        trackReceiver = new TrackReceiver();
        getApplicationContext().registerReceiver(trackReceiver, new IntentFilter(Constant.ACCOUNT_TRACK));
        locationReceiver = new LocationReceiver();
        getApplicationContext().registerReceiver(locationReceiver, new IntentFilter(Constant.ACCOUNT_LAT_LNG));
        mSharePreference = SharePreferenceManager.getInstance(mContext);
//        templateTextViewRight.setText("修改密码");
//        templateTextViewRight.setVisibility(View.VISIBLE);
        getExtras();
        findView();
        setListener();
    }

    public void getExtras() {
        vinList = (VinList) getIntent().getSerializableExtra("vinList");
        userEntity = (UserEntity) getIntent().getSerializableExtra("userEntity");
        if (vinList.getResult().size() > 0) {
            titleView.setText(userEntity.getAccount_number());
        }

        WaitingDialogControll.showWaitingDialog(this);
        LoginAccountBiz loginAccountBiz = new LoginAccountBiz();
        loginAccountBiz.loginByCarBiz(userEntity);
        //selCarsBiz.selCarsByEqNumerBiz(mUserEntity.getEqNo());

    }

    private void findView() {


        //初始化地图控制器
        if (aMap == null) {
            aMap = mapView.getMap();
            liner_search = (LinearLayout) findViewById(R.id.liner_search);
            //禁止地图旋转手势
            aMap.getUiSettings().setRotateGesturesEnabled(false);
            aMap.setOnMapClickListener(this);//对amap添加单击地图事件监听器
            aMap.setOnMarkerClickListener(this);// 设置点击marker事件监听器
            aMap.setInfoWindowAdapter(this);// 设置自定义InfoWindow样式
            aMap.moveCamera(CameraUpdateFactory.zoomTo(13));

        }
        aMap.clear();

        aMap.setOnCameraChangeListener(new AMap.OnCameraChangeListener() {
            @Override
            public void onCameraChange(CameraPosition cameraPosition) {

            }

            @Override
            public void onCameraChangeFinish(CameraPosition cameraPosition) {
                currentZoom = cameraPosition.zoom;
            }
        });

        mBackImageButton = (ImageButton) findViewById(R.id.title_back_left);


        mTitleTv = (TextView) findViewById(R.id.title_name_text);
        if (vinList.getResult().size() > 0) {
            mTitleTv.setText(userEntity.getAccount_number());
        }

        mTvRight = findViewById(R.id.title_tv_rights);
        mTvRight.setText("修改密码");
        mTvRight.setVisibility(View.VISIBLE);

    }

    private void setListener() {
        mBackImageButton.setOnClickListener(this);
        mTvRight.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ArrayList<String> mData = new ArrayList<>();
                for(int i = 0; i<vinList.getResult().size(); i++){
                    mData.add(vinList.getResult().get(i).getEqId() + "");
                }
                Intent intent = new Intent(VinIndexActivity.this, ResetPwdActivity.class);
                intent.putExtra("type", 1);
                intent.putStringArrayListExtra("mData", mData);
                startActivity(intent);
            }
        });
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.title_back_left) {
            finish();
        }
    }

    @Override
    protected void onDestroy() {
        EventBus.getDefault().unregister(this);
        super.onDestroy();
        mapView.onDestroy();
        getApplicationContext().unregisterReceiver(selCarsReceiver);
        getApplicationContext().unregisterReceiver(trackReceiver);
        getApplicationContext().unregisterReceiver(locationReceiver);
    }

    @Override
    protected void onResume() {
        super.onResume();
        //在activity执行onResume时执行mMapView.onResume ()，重新绘制加载地图
        mapView.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
        //在activity执行onPause时执行mMapView.onPause ()，暂停地图的绘制
        mapView.onPause();
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        //在activity执行onSaveInstanceState时执行mMapView.onSaveInstanceState (outState)，保存地图当前的状态
        mapView.onSaveInstanceState(outState);
    }

    /**
     * 地图点击事件回调方法
     */
    @Override
    public void onMapClick(LatLng latLng) {
        log_e("地图被点击了！！");
//        if (null != showMarker && showMarker.isInfoWindowShown()) {
//            if (oldShowFlag) {
//                showMarker.hideInfoWindow();//这个是隐藏infowindow窗口的方法
//            }
//
//        }
        if (oldShowFlag) {
            showMarker.hideInfoWindow();//这个是隐藏infowindow窗口的方法
            oldShowFlag = false;
        }
    }

    /**
     * Mark点击事件回调方法
     */
    @Override
    public boolean onMarkerClick(Marker marker) {
        //oldShowFlag = marker.isInfoWindowShown();
        ShowDialog(marker);
        if(isFirst){
            return false;//返回:true:表示点击marker后,marker不会移动到地图中心；返回false表示点击marker后,marker会自动移动到地图中心。
        }else {
            return true;
        }
    }

    private float currentZoom = 13;

    public void ShowDialog(Marker marker) {
        // 设置地图中心点在屏幕的位置
        showMarker = marker;
        if (marker.isInfoWindowShown()) {
            marker.hideInfoWindow();
            oldShowFlag = false;
        } else {
            showMarker.showInfoWindow();
            aMap.setPointToCenter(WindowSizeUtil.getWidth(mContext) / 2, WindowSizeUtil.getHeight(mContext) / 5 * 4);
            marker.showInfoWindow();
            aMap.moveCamera(CameraUpdateFactory.zoomTo(currentZoom));
            aMap.moveCamera(CameraUpdateFactory.changeLatLng(new LatLng(marker.getPosition().latitude, marker.getPosition().longitude)));
            oldShowFlag = true;
        }

    }

    public void showMarkDialog() {
        // 设置地图中心点在屏幕的位置
        aMap.setPointToCenter(WindowSizeUtil.getWidth(mContext) / 2, WindowSizeUtil.getHeight(mContext) / 5 * 4);
//        showMarker = poiOverlay.getMarkerByPosition(0);
//        poiOverlay.getMarkerByPosition(0).showInfoWindow();
        //aMap.moveCamera(CameraUpdateFactory.changeLatLng(new LatLng(equipmentEntity.getResult().get(0).getPoint().getLat(), equipmentEntity.getResult().get(0).getPoint().getLng())));
    }

    public void closeShowDialog() {
        // 设置地图中心点在屏幕的位置
        showMarker = poiOverlay.getMarkerByPosition(0);
        poiOverlay.getMarkerByPosition(0).hideInfoWindow();
    }

    /**
     * 设置自定义InfoWindow样式的回调方法
     * infocontents事件回调
     * 注意：API优先回调getInfoWindow ，如果返回的是null，会再回调getInfoContents。
     */
    @Override
    public View getInfoWindow(Marker marker) {
        int possion = Integer.valueOf(marker.getTitle());
        return getInfoView(possion);
    }

    /**
     * 设置自定义InfoWindow样式的回调方法
     * infowindow事件回调
     */
    @Override
    public View getInfoContents(Marker marker) {
        int possion = Integer.valueOf(marker.getTitle());
        return getInfoView(possion);
    }

    private View getInfoView(final int possion) {
        final View view = LayoutInflater.from(mContext).inflate(R.layout.layout_marker_infowindow, null);
        popView = view;
        //不显示更多选项
        view.findViewById(R.id.liner_info_below).setVisibility(View.GONE);
        //设置车主姓名
        if (vinList.getResult().size() > 0) {
            ((TextView) view.findViewById(R.id.tv_driverName)).setText(vinList.getResult().get(possion).getOwnerName());
        }
        //设置设备编号
        ((TextView) view.findViewById(R.id.tv_eqno)).setText(vinList.getResult().get(possion).getEqNo());
        //存储设备状态
        mSharePreference.put(Constant.ACCOUNT_STATUS, vinList.getResult().get(possion).getStatus());
        //存储车主姓名
        mSharePreference.put(Constant.ACCOUNT_NAME, vinList.getResult().get(possion).getOwnerName());
        ((TextView) view.findViewById(R.id.tv_time)).setText(vinList.getResult().get(possion).getActTime());
        tv_dress = view.findViewById(R.id.tv_dress);

        ((TextView) view.findViewById(R.id.tv_flag)).setText(vinList.getResult().get(possion).getCnStatus());
        ((TextView) view.findViewById(R.id.tv_post_type)).setText(vinList.getResult().get(possion).getPoint().getPostType());
        if (isFirst) {
            isFirst = false;
            closeShowDialog();
            final TrackBiz trackBiz = new TrackBiz();

//            trackBiz.trackBiz(mUserEntity.getEqNo(),null,listItem.get(possion),Constant.ACCOUNT_TRACK,true);
        }


        //存储定位时间
//
//        new Thread(new Runnable() {
//            @Override
//            public void run() {
//                // 模拟耗时的操作,保证地址加载完成后进行赋值
//                try {
//                    Thread.sleep(1000);
//                } catch (InterruptedException e) {
//                    e.printStackTrace();
//                }
//                // 更新主线程ＵＩ
//                runOnUiThread(new Runnable() {
//                    @Override
//                    public void run() {
//                        ((TextView)view.findViewById(R.id.tv_time)).setText(possionTime);
//                    }
//                });
//
//            }
//        }).start();
//
//        //存储速度
//
        //存储当前地址（通过经纬度转换为地理位置）
        double lat=vinList.getResult().get(possion).getPoint().getLat();
        double lng=vinList.getResult().get(possion).getPoint().getLng();
        LatLonPoint latLonPoint=new LatLonPoint(lat,lng);
        geocodeSearch=new GeocodeSearch(this);
        geocodeSearch.setOnGeocodeSearchListener(this);
        // 第一个参数表示一个Latlng，第二参数表示范围多少米，第三个参数表示是火系坐标系还是GPS原生坐标系
        RegeocodeQuery query = new RegeocodeQuery(latLonPoint, 200,GeocodeSearch.AMAP);
        geocodeSearch.getFromLocationAsyn(query);
        new Thread(new Runnable() {
            @Override
            public void run() {
                // 模拟耗时的操作,保证地址加载完成后进行赋值
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                // 更新主线程ＵＩ
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        ((TextView)view.findViewById(R.id.tv_dress)).setText(addressName);
                    }
                });

            }
        }).start();
        /**
         * 设置按钮点击事件
         */
        //更多
        view.findViewById(R.id.liner_info_more).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (flag == 0) {//点击全选
                    flag = 1;
                    //显示更多选项
                    view.findViewById(R.id.liner_info_below).setVisibility(View.VISIBLE);
                } else {
                    flag = 0;
                    //显示更多选项
                    view.findViewById(R.id.liner_info_below).setVisibility(View.GONE);
                }
            }
        });
        //历史轨迹
        view.findViewById(R.id.liner_history).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (ButtonUtil.isFastClick()) {
                    // IntentUtil.gotoActivity(mContext,HistoryTraceActivity.class,false,map);
                    Intent intent = new Intent();
                    intent.putExtra("eqNo", vinList.getResult().get(possion).getEqNo());//存入当前设备
                    intent.putExtra("carName", vinList.getResult().get(possion).getOwnerName());//存入当前车主姓名
                    intent.setClass(mContext, HistoryTraceActivity.class);
                    startActivity(intent);
                }
            }
        });
        //一键追车
        view.findViewById(R.id.liner_navi).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (ButtonUtil.isFastClick()) {
                    Intent intent = new Intent(mContext, AccountChaseCarAcitivty.class);
                    TrackEntity data = new TrackEntity();
                    TrackEntity.Result dataResult = new TrackEntity.Result();
                    dataResult.setGdLat(vinList.getResult().get(possion).getPoint().getLat());
                    dataResult.setGdLng(vinList.getResult().get(possion).getPoint().getLng());
                    ArrayList<TrackEntity.Result> results = new ArrayList<>();
                    results.add(dataResult);
                    data.setResults(results);
                    intent.putExtra(Constant.ACCOUNT_NAVIGATION, data);
                    startActivity(intent);
                }
            }
        });
        //重新定位
        view.findViewById(R.id.liner_reposition).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (ButtonUtil.isFastClick()) {
                    WaitingDialogControll.showWaitingDialog(mContext);
                    //开启刷新状态
                    closeShowDialog();
                    final TrackBiz trackBiz = new TrackBiz();
                    trackBiz.trackBizNoCar(vinList.getResult().get(possion).getEqNo(), null, vinList.getResult().get(possion), Constant.ACCOUNT_TRACK, true);
                }
            }
        });
        //实时跟踪
        view.findViewById(R.id.liner_track).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (ButtonUtil.isFastClick()) {
                    // WaitingDialogControll.showWaitingDialog(mContext);
                    Intent intent = new Intent();
                    intent.putExtra("eqNo", vinList.getResult().get(possion).getEqNo());//存入当前设备
                    intent.putExtra("ownerName", vinList.getResult().get(possion).getOwnerName());
                    intent.setClass(mContext, TracingActivity.class);
                    startActivity(intent);
                }
            }
        });
        //单个设备告警
        view.findViewById(R.id.liner_notice).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (ButtonUtil.isFastClick()) {
                    Intent intent = new Intent();
                    intent.putExtra("eqNo", vinList.getResult().get(possion).getEqNo());//存入当前设备编码
                    intent.putExtra("deptId", vinList.getResult().get(possion).getEgId());//存入当前部门编码
                    intent.putExtra("eqName", vinList.getResult().get(possion).getOwnerName());//存入姓名
                    intent.setClass(mContext, AlarmListActivity.class);
                    startActivity(intent);

                }
            }
        });

        //用户信息
        view.findViewById(R.id.liner_user_content).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (ButtonUtil.isFastClick()) {
                    Intent intent = new Intent();
                    intent.putExtra("eqNo", vinList.getResult().get(possion).getEqNo());//设备号
                    intent.putExtra("deptId", vinList.getResult().get(possion).getEgId());//型号
                    intent.setClass(mContext, AccountUserInfoActivity.class);
                    startActivity(intent);

                }
            }
        });


        return view;
    }

    /**
     * 通过经纬度转化为地理位置
     */
    @Override
    public void onRegeocodeSearched(RegeocodeResult result, int rCode) {
        if (rCode == 1000) {
            if (result != null && result.getRegeocodeAddress() != null
                    && result.getRegeocodeAddress().getFormatAddress() != null) {
                addressName = result.getRegeocodeAddress().getFormatAddress() + "附近";
            } else {
                addressName = "当前地址获取失败";
            }
        } else {
            addressName = "当前地址获取失败";
        }
    }

    @Override
    public void onGeocodeSearched(GeocodeResult result, int rCode) {

    }

    class SelCarsReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
            WaitingDialogControll.dismissWaitingDialog();
//            equipmentEntity = (VinList) intent.
//                    getSerializableExtra(Constant.KEY_DATA);
//            vinList.getResult().clear();
//            vinList.getResult().addAll(equipmentEntity.getResult());
            equipmentEntity = (VinList) getIntent().getSerializableExtra("vinList");
            if ((Constant.STATUS_OK + "").equals(equipmentEntity.getStatus())) {
                markCarsOnMap(equipmentEntity.getResult(), false);
                showMarkDialog();
            } else if ((Constant.STATUS_NETWORK_ERROR + "").equals(equipmentEntity.getStatus())) {
                Toast.makeText(mContext, "加载失败", Toast.LENGTH_SHORT).show();
            } else if ((Constant.STATUS_NO_NET + "").equals(equipmentEntity.getStatus())) {
                Toast.makeText(mContext, "请检查网络", Toast.LENGTH_SHORT).show();
            }

        }
    }

    /**
     * 设置Markers方法
     */

    private void markCarsOnMap(List<VinList.Vin> items, boolean isLoadMore) {
        if (!isLoadMore) {
            aMap.clear();
        }
        if (items.size() > 0) {
            List<BitmapDescriptor> b = VinListPoiOverlay.getBitmap(items, mContext);//设置图片状态

            poiOverlay = new VinListPoiOverlay(aMap, items, b, (WindowSizeUtil.getWidth(mContext)) / 8);//通过自定的Mark管理类poiOverlay来管理
            poiOverlay.removeFromMap();
            poiOverlay.addToMap();
            poiOverlay.zoomToSpan();
            aMap.moveCamera(CameraUpdateFactory.zoomTo(15));
        }
    }

    VinList.Vin itemNew;

    //接收实时跟踪数据的广播
    class TrackReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
            if(intent.getSerializableExtra(Constant.KEY_DATA) == null){
                return;
            }
            trackEntity = (TrackEntity) intent.
                    getSerializableExtra(Constant.KEY_DATA);
            itemNew = (VinList.Vin) intent.
                    getSerializableExtra(Constant.KEY_DATA2);
            if (trackEntity != null && trackEntity.getResults() != null && trackEntity.getResults().size() > 0 && !trackEntity.getResults().get(0).getImportTime().equals("null")) {
                possionTime = trackEntity.getResults().get(0).getImportTime();

            } else {
                possionTime = "正在获取时间";
            }

            if (popView != null) {
                ((TextView) popView.findViewById(R.id.tv_time)).setText(trackEntity.getResults().get(0).getImportTime());
                ((TextView) popView.findViewById(R.id.tv_post_type)).setText(trackEntity.getResults().get(0).getPostType());
                String status = trackEntity.getResults().get(0).getStatus();
                if ("2".equals(status)) {
                    ((TextView) popView.findViewById(R.id.tv_flag)).setText("离线");
                } else if ("3".equals(status)) {
                    ((TextView) popView.findViewById(R.id.tv_flag)).setText("未启用");
                } else {
                    ((TextView) popView.findViewById(R.id.tv_flag)).setText("在线");
                }

                new LocationBiz().getAddRessWithLatAndLng(trackEntity.getResults().get(0).getGdLat(), trackEntity.getResults().get(0).getGdLng(), Constant.ACCOUNT_LAT_LNG);
                if (itemNew != null) {
                    itemNew.getPoint().setLat(trackEntity.getResults().get(0).getGdLat());
                    itemNew.getPoint().setLng(trackEntity.getResults().get(0).getGdLng());
                    itemNew.getPoint().setDir(trackEntity.getResults().get(0).getDir());
                    delItemOld(itemNew);
                    vinList.getResult().add(itemNew);
                    markCarsOnMap(equipmentEntity.getResult(), false);
                    showMarker = poiOverlay.getMarkerByPosition(vinList.getResult().size() - 1);

                    aMap.moveCamera(CameraUpdateFactory.changeLatLng(new LatLng(trackEntity.getResults().get(0).getGdLat(), trackEntity.getResults().get(0).getGdLng())));
                }
            }
        }
    }

    private void delItemOld(VinList.Vin item) {
        for (int i = 0; i < vinList.getResult().size(); i++) {
            if (vinList.getResult().get(i).getEqNo().equals(item.getEqNo())) {
                vinList.getResult().remove(i);
                break;
            }
        }
    }

    class LocationReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
            WaitingDialogControll.dismissWaitingDialog();
            LocationBean locationBean = (LocationBean) intent.
                    getSerializableExtra(Constant.KEY_DATA);
            if (locationBean.getStatus() == Constant.STATUS_OK) {
                ((TextView) popView.findViewById(R.id.tv_dress)).setText(locationBean.getRegeocode().getFormatted_address());
                addressName = locationBean.getRegeocode().getFormatted_address();
                showMarkDialog();
            }

        }
    }


    public void showData(VinList mVinList) {
        markCarsOnMap(mVinList.getResult(), false);
        showMarkDialog();
    }
    //接收修改密码结果后退出重新登录
    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onDataSynEvent(VinEvent vinEvent) {
        finish();
    }
}
